package dictservicelogic

import (
	"context"
	"encoding/json"

	"github.com/blog-zero/rpc/sys/internal/svc"
	"github.com/blog-zero/rpc/sys/sysclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type DictChildenParentsCountLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDictChildenParentsCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DictChildenParentsCountLogic {
	return &DictChildenParentsCountLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DictChildenParentsCountLogic) DictChildenParentsCount(in *sysclient.DictChildenParentsCountReq) (*sysclient.DictChildenParentsCountResp, error) {
	count, err := l.svcCtx.DictChildenModel.ParentsCountByIds(l.ctx, in.Ids)

	if err != nil {
		reqStr, _ := json.Marshal(in)
		logx.WithContext(l.ctx).Errorf("查询根据ids查询关联所有子字典信息失败,参数:%s,异常:%s", reqStr, err.Error())
		return nil, err
	}
	return &sysclient.DictChildenParentsCountResp{
		ParentsCount: count,
	}, nil
}
